<template>
	<view class="content">
		<view class="top_box">
			<text>买入金额</text>
			<text>交易规则</text>
		</view>
		<view class="ipt_box">
			<text>￥</text>
			<input
				placeholder-class="pla"
				type="text"
				value=""
				class="inpt"
				placeholder="最低买入100.00元"
				v-model="ipt"
			/>
			<view class="img_box">
				<image
					src="../../static/image/icon_guotaijinluhunhe_qingkong@2x.png"
					mode=""
				></image>
			</view>
		</view>
		<view class="text_c">
			<text @tap="ipt = 1000">1000</text>
			<text @tap="ipt = 3000">3000</text>
			<text @tap="ipt = 5000">5000</text>
		</view>
		<view class="text_d">
			<text>买入费率0.13%，赎回费率见交易规则</text>
			<text>
				预计06月12日(周三)根据06月11日(周二)的净值确认份额
			</text>
		</view>
		<view class="payment_box">
			<view class="left_t"><text>付款方式</text></view>
			<view class="right_t">
				<view class="t_a">
					<text>我的钱包</text>
					<text>其他支付方式</text>
				</view>
				<view class="i_a">
					<image
						src="../../static/image/icon_guotaijinluhunhe_zhifufangshi@2x.png"
						mode=""
					></image>
				</view>
			</view>
		</view>
		<view class="check_box">
			<u-checkbox-group>
				<u-checkbox
					v-model="item.checked"
					v-for="(item, index) in list"
					:key="index"
					:name="item.name"
					shape="circle"
					size="26rpx"
					label-size="24rpx"
				>
					<text class="text_m">
						我已阅读
						<text class="text_check">相关协议</text>
						，理解其内容并承担相关风险
					</text>
				</u-checkbox>
			</u-checkbox-group>
		</view>
		<!-- 评测弹窗 -->
		<view>
			<u-popup
				negative-top="500"
				width="546"
				border-radius="12"
				mode="center"
				v-model="show"
			>
				<view class="pop_box">
					<view class="text_pop">
						<text>交易提醒</text>
						<text>
							根据金融监管机构要求,在您投资前请先完成风险测评问卷,进一步了解自身的投资风格及风险承受能力(预计[耗时80秒])。
						</text>
						<text>
							在您购买产品时,我们将根据测评结果，进行风险等级匹配检查和风险提示,请您关注。
						</text>
					</view>
					<view class="btn_pop">
						<view class="pop_l">取消</view>
						<view class="pop_r" @tap="moneyPop">
							开始评测
						</view>
					</view>
				</view>
			</u-popup>
		</view>
		<!-- 输出密码 -->
		<view>
			<u-popup
				negative-top="500"
				border-radius="12"
				mode="center"
				v-model="money"
				:closeable="true"
				close-icon-size="16"
				close-icon-pos="top-left"
			>
				<view class="money_box">
					<text class="mey_nav">请输入支付密码</text>
					<u-message-input
						class="inpts"
						mode="box"
						:breathe="true"
						:focus="true"
						width="56"
						:maxlength="6"
						font-size="24"
						:bold="false"
						@finish="finish"
					></u-message-input>
					<text class="mey_btm">忘记密码？</text>
				</view>
			</u-popup>
		</view>
		<button @tap="paymentBtn" class="btn" type="default">
			立即支付
		</button>
		<view><u-toast ref="uToast" /></view>
	</view>
</template>

<script>
import apis from '../../api/apis.js';
export default {
	data() {
		return {
			list: [
				{
					name: '协议',
					checked: false,
					disabled: false,
				},
			],
			show: false,
			money: false,
			ipt: '',
			fundCode: '',
			simplifyName: '',
			userId: '',
		};
	},
	onLoad(option) {
		
		this.fundCode = option.fundCode;
		this.simplifyName = option.simplifyName;
		this.userId = uni.getStorageSync('id');
		
	},
	onUnload() {
		clearTimeout();
	},
	methods: {
		moneyPop() {
			uni.navigateTo({
				url:'../Risk/Risk'
			})
		},
		paymentBtn() {
			if (this.list[0].checked == true) {
				if (uni.getStorageSync('Risk')!='') {
					this.money = true;
				} else{
					this.show = true;
				}
			} else {
				this.$refs.uToast.show({
					title: '请选勾选',
					type: 'warning',
				});
			}
		},
		finish(e) {
			this.getFundOrder(e);
		},
		async getFundOrder(e) {
			let result = await apis.manager.fundOrder({
				fundCode: this.fundCode,
				simplifyName: this.simplifyName,
				userId: this.userId,
			});
			console.log(result);
			if (result.code == 200) {
				let res = await apis.manager.fundPay({
					balance: this.ipt,
					orderId: result.data,
					payPassWord: e,
					userId: this.userId,
				});
				if (res.code == 200) {
					if (res.data.code == 200) {
						this.$refs.uToast.show({
							title: res.data.data,
							type: 'success',
							duration: 1000,
						});
						setTimeout(() => {
							uni.navigateTo({
								url:
									'../purchase_Ba3/purchase_Ba3?name=' +
									this.simplifyName +
									'&text=' +
									this.ipt,
							});
						}, 1500);
					} else {
						this.$refs.uToast.show({
							title: res.data.data,
							type: 'error',
							duration: 1000,
						});
					}
				} else {
					this.$refs.uToast.show({
						title: '购买失败',
						type: 'error',
					});
				}
			} else {
				this.$refs.uToast.show({
					title: '购买失败,订单未生成',
					type: 'error',
				});
			}
		},
	},
};
</script>

<style lang="scss">
@import 'css/payment_Bthree.scss';
</style>
